/*
 * Copyright (C) 2014 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose :
 *
 * Feature : The file includes the following modules and sub-modules
 *           (1)
 */
#include "app_basic.h"

#include "feature_export_api.h"

unsigned int cf_gen_vtfd_rule(va_list argp)
{
    OMCI_VLAN_OPER_ts *pVlanRule = va_arg(argp, OMCI_VLAN_OPER_ts *);
    OMCI_VLAN_ACT_ts *pCVlanAct = &pVlanRule->cTagAct;
	OMCI_VLAN_OUT_ts *pOutVlan = &pVlanRule->outStyle;
    MIB_TABLE_VLANTAGOPCFGDATA_T *pVlanTagOpCfg  = va_arg(argp, MIB_TABLE_VLANTAGOPCFGDATA_T *);
    va_end(argp);

    if (0xF != pVlanTagOpCfg->UsTagOpMode)
    	return FAL_ERR_DISABLE;

    pVlanRule->filterRule.filterStagMode = VLAN_FILTER_NO_TAG;
	pVlanRule->filterRule.filterCtagMode = VLAN_FILTER_NO_TAG;
	pCVlanAct->vlanAct = VLAN_ACT_ADD;
	pCVlanAct->vidAct  = VID_ACT_ASSIGN;
	pCVlanAct->priAct  = PRI_ACT_ASSIGN;
	pCVlanAct->assignVlan.pri = (pVlanTagOpCfg->UsTagTci >> 13);
	pCVlanAct->assignVlan.vid = (0xfff & pVlanTagOpCfg->UsTagTci);
	pCVlanAct->assignVlan.tpid = UINT_MAX;
	pOutVlan->outTagNum = 1;
	memcpy(&pOutVlan->outVlan, &pCVlanAct->assignVlan, sizeof(OMCI_VLAN_ts));

	return FAL_OK;
}

unsigned int cf_check_vtfd_mode(va_list argp)
{
    MIB_TABLE_VLANTAGOPCFGDATA_T *pVlanTagOpCfg  = va_arg(argp, MIB_TABLE_VLANTAGOPCFGDATA_T *);
    va_end(argp);

    if (0xF != pVlanTagOpCfg->UsTagOpMode)
    	return FAL_ERR_DISABLE;

    return FAL_OK;
}

unsigned int feature_module_init(unsigned int moduleID)
{
    if (FAL_OK != feature_api_register(FEATURE_API_BDP_00000008_GEN_RULE, moduleID, &cf_gen_vtfd_rule))
        return FAL_FAIL;

    if (FAL_OK != feature_api_register(FEATURE_API_BDP_00000008_CHECK_MODE, moduleID, &cf_check_vtfd_mode))
        return FAL_FAIL;

    return FAL_OK;
}

unsigned int feature_module_exit(void)
{
	feature_api_unregister(FEATURE_API_BDP_00000008_GEN_RULE);
	feature_api_unregister(FEATURE_API_BDP_00000008_CHECK_MODE);

    return FAL_OK;
}

